package com.hengpeng.itfin.domain.partner.chinapnr.util;

import java.math.BigInteger;

public class RSAEncrypt
{
  private BigInteger p;
  private BigInteger q;
  private BigInteger a;
  private BigInteger b;
  private BigInteger u;
  private BigInteger dP;
  private BigInteger dQ;

  public RSAEncrypt(PrivateKey paramPrivateKey)
  {
    try
    {
      this.p = new BigInteger(1, paramPrivateKey.Prime[0]);
      this.q = new BigInteger(1, paramPrivateKey.Prime[1]);
      this.u = new BigInteger(1, paramPrivateKey.Coefficient);
      this.dP = new BigInteger(1, paramPrivateKey.PrimeExponent[0]);
      this.dQ = new BigInteger(1, paramPrivateKey.PrimeExponent[1]);
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
    }
  }

  public String EncryptMessage(byte[] paramArrayOfByte)
  {
    BigInteger localBigInteger1 = new BigInteger(1, paramArrayOfByte);
    String str;
    try
    {
      BigInteger localBigInteger2 = localBigInteger1.mod(this.p);
      BigInteger localBigInteger3 = localBigInteger1.mod(this.q);
      this.a = localBigInteger2.modPow(this.dP, this.p);
      this.b = localBigInteger3.modPow(this.dQ, this.q);

      BigInteger localBigInteger4;
	if (this.a.compareTo(this.b) >= 0)
      {
        localBigInteger4 = this.a.subtract(this.b);
      }
      else {
        localBigInteger4 = this.b.subtract(this.a);
        localBigInteger4 = this.p.subtract(localBigInteger4);
      }
      localBigInteger4 = localBigInteger4.mod(this.p).multiply(this.u).mod(this.p).multiply(this.q).add(this.b);
      for (str = localBigInteger4.toString(16); str.length() < 256; str = '0' + str);
    }
    catch (ArithmeticException localArithmeticException) {
      return null;
    }
    return str;
  }
}
